﻿using System.Collections.Generic;
using gixoom.Dom.Block;

namespace gixoom.Dom.Storage.File
{
    internal class FileNameByBlockIdDictionary: IBlockIdToFileNameMapping
    {
        private IDictionary<IBlockId, string> fileNameByBlockId = new Dictionary<IBlockId, string>();

        /// <summary>
        /// Returns file name associated with the specified block id.
        /// </summary>
        /// <param name="blockId">block id</param>
        /// <returns>file name associated with the specified block id</returns>
        /// <exception cref="System.ArgumentNullException"><i>blockId</i> is a null reference.</exception>
        public string GetFileNameByBlockId(IBlockId blockId)
        {
            Ensure.ArgumentNotNull(blockId, "blockId");

            string fileName;
            fileNameByBlockId.TryGetValue(blockId, out fileName);

            return fileName;
        }

        /// <summary>
        /// Associates the specified <i>fileName</i> with the specified <i>blockId</i>.
        /// </summary>
        /// <param name="fileName">the file name which will be associated with the specified block id</param>
        /// <param name="blockId">block id</param>
        /// <exception cref="System.ArgumentNullException">One of the arguments is a null reference.</exception>
        /// <exception cref="System.ArgumentException"><i>fileName</i> is an empty string.</exception>
        public void SetFileNameByBlockId(string fileName, IBlockId blockId)
        {
            Ensure.ArgumentNotNull(fileName, "fileName");
            Ensure.StringArgumentNotEmpty(fileName, "fileName");
            Ensure.ArgumentNotNull(blockId, "blockId");

            fileNameByBlockId[blockId] = fileName;
        }
    }
}
